/*************************************************
 * 
 * Copyright by Bruno Eberhard
 * 
 * Created on 29.07.2005
 *
 *************************************************/
package fightplan.core;

import java.awt.Component;
import java.awt.Container;

import javax.swing.JComponent;

public class Util {

	public static Object getProperty(Component component, Object key) {
		JComponent jcomponent = getPropertyHolder(component, key);
		return jcomponent != null ? jcomponent.getClientProperty(key) : null;
	}

	public static JComponent getPropertyHolder(Component component, Object key) {
		while (component != null) {
			if (component instanceof JComponent) {
				JComponent jcomponent = (JComponent) component;
				Object value = jcomponent.getClientProperty(key);
				if (value != null)
					return jcomponent;
			}
			if (component instanceof Container) {
				component = ((Container) component).getParent();
			} else {
				return null;
			}
		}
		return null;
	}

	public static boolean equals(Object o1, Object o2) {
		if (o1 == null) {
			return o2 == null;
		} else {
			return o1.equals(o2);
		}
	}

}
